<?php
class Admin_IndexController extends Zendvn_Controller_Action{
	
	public function init(){
		
		parent::init();		
		$this->_templateObj->setPath(TEMPLATE_PATH . '/admin');	
		$this->_templateObj->setSectionConfig('login');
		$this->_templateObj->load();	
		/*====================================================
		 * Load Zendvn Translate for Controller
		*====================================================*/
		$this->_langObj->setLangFile(array('validate.tmx'));
		Zend_Registry::set('Zend_Translate',$this->_langObj->generate());
		$this->view->arrParam = $this->_arrParam;
	}
	
	public function indexAction(){
		$this->_redirect('/admin/admin-user/index');
		$this->_helper->viewRenderer->setNoRender();
	}
	
	public function loginAction(){
		if($this->_request->isPost()){
			$validator = new Admin_Form_ValidateLogin($this->_arrParam);
			if($validator->isVaild()){
				$this->view->errors = $validator->getMessageErrors();
				$this->view->Item = $validator->getData();
			}else{
				$auth = new Zendvn_System_Auth();
	
				if($auth->login($this->_arrParam) == true){
					$auth = Zend_Auth::getInstance();
					$info = new Zendvn_System_Info();
					$info->setInfo($auth);
					if($this->_arrParam['action']!='login'){
						$this->_redirect($this->_currentController);
					}
				}
			}
		}
	}
	
	public function logoutAction(){
		$user_info = new Zend_Session_Namespace('user_login');
		$user_info->logout = true;
	
		$auth = new Zendvn_System_Auth();
		$info = new Zendvn_System_Info();
		$info->clearInfo();
		$auth->logout();
		$this->_redirect('/default');
	}
	public function noAccessAction(){
	
	}
}